import { _decorator, Toggle, ToggleContainer } from 'cc';
import { PanelBase } from '../../Basic/UI/PanelBase';
import { LayerType } from '../../Basic/Config/BaseEnum';
import { List } from '../../Basic/Component/List';
import { PoolFactory } from '../../Basic/Component/PoolFactory';
import { HandbookModel } from './HandbookModel';
const { ccclass, property } = _decorator;

@ccclass('HandbookPanel')
export class HandbookPanel extends PanelBase {
  panelLayer: LayerType.DialogLayer = LayerType.DialogLayer;

  @property(List)
  itemList: List;

  @property(PoolFactory)
  poolFac: PoolFactory;

  @property(ToggleContainer)
  togCtr: ToggleContainer;

  protected onEnable(): void {
    super.onEnable();
    HandbookModel.Ins().itemList = this.itemList;
    HandbookModel.Ins().poolFac = this.poolFac;
    HandbookModel.Ins().togCtr = this.togCtr;
    this.itemList.enabled = false;
    HandbookModel.Ins().initItemList();
  }

  protected onDisable(): void {
    this.itemList.enabled = false;
  }

  onClickBtn(t: Touch, data) {
    const key = data.toString();
    switch (key) {
      case 'close':
        this.clickClose();
        break;
    }
  }

  onCheckEvt(t: Toggle) {
    HandbookModel.Ins().changeItemList(t.node.name);
  }
}
